/*
 * run_config_packet.h
 *
 *  Created on: 20.07.2013
 *      Author: SpirTanol
 */

#ifndef RUN_CONFIG_PACKET_H_
#define RUN_CONFIG_PACKET_H_

#include "packets/data_packet.h"
#include "global.h"

class RunConfigPacket : public DataPacket
{
	enum Reg
	{
		R_TIME,
		R_CUR_NOM = R_TIME + 2,
		R_COMPLETENESS,
		R_CUR_DURATION,

		R_SIZE = R_CUR_DURATION + 32,
	};
	ushort oData[R_SIZE];
	int oCurScale;

public:
	RunConfigPacket(int curScale) { init(curScale); }
	RunConfigPacket(const RunConfigPacket *packet);
	~RunConfigPacket() {}

	inline uint time() const { return *(uint*)&oData[R_TIME]; }
	inline double curNom() const { return double(oData[R_CUR_NOM]) / double(oCurScale); }
	inline uint completeness() const { return uint(oData[R_COMPLETENESS]); }
	inline double completenessPercent() const { return double(oData[R_COMPLETENESS]) / 65535.0; }
	inline double curDuration(int idx) const { return double(oData[R_CUR_DURATION + idx]) * 0.01; }

	RunConfigPacket *clone() const { return new RunConfigPacket(this); } // [virtual]

private:
	inline void init(int curScale) { oCurScale = curScale; addPart(Part(oData, R_SIZE, 201)); }

};

class RunConfigProgressPacket : public DataPacket
{
	enum Reg
	{
		R_STATE,
		R_PROGRESS,
		R_TIME,
		R_CUR_NOM = R_TIME + 2,
		R_COMPLETENESS,

		R_SIZE,
	};
	ushort oData[R_SIZE];

public:
	enum State
	{
		S_NO_PROCESS = 0,
		S_IN_PROCESS = 1,
		S_COMPLETE = 2,
	};

	RunConfigProgressPacket() { init(); }
	RunConfigProgressPacket(const RunConfigProgressPacket *packet);
	~RunConfigProgressPacket() {}

	inline State state() const { switch (oData[R_STATE]) { case S_IN_PROCESS: return S_IN_PROCESS; case S_COMPLETE: return S_COMPLETE; } return S_NO_PROCESS; }
	inline uint progress() const { return uint(oData[R_PROGRESS]); }
	inline uint time() const { return *(uint*)&oData[R_TIME]; }
	inline uint completeness() const { return uint(oData[R_COMPLETENESS]); }
	inline double completenessPercent() const { return double(oData[R_COMPLETENESS]) / 65535.0; }

	RunConfigProgressPacket *clone() const { return new RunConfigProgressPacket(this); } // [virtual]

private:
	inline void init() {  oData[R_STATE] = S_COMPLETE; addPart(Part(oData, R_SIZE, 199)); }

};

#endif /* RUN_CONFIG_PACKET_H_ */
